<?php
/**
 * This file is part of Hyperf Mall.
 *
 * @link     https://gitee.com/scwlkj/hyperf_mall
 * @contact  hyperf_mall@163.com
 */

namespace App\JsonRpc;

use App\Repository\CartRepository;
use Hyperf\RpcServer\Annotation\RpcService;
use App\JsonRpc\Interfaces\CartServiceInterface;

/**
 * @RpcService(name="Orders::CartService", protocol="jsonrpc", server="jsonrpc")
 */
class CartService extends BaseService implements CartServiceInterface
{
    public function init()
    {
        $this->repository = CartRepository::getInstance();
    }

    /**
     * Notes:自增
     * Author: Bruce.z
     * DateTime: 2022/6/30 16:55
     * @param int $id
     * @param int $num
     * @return mixed
     */
    public function incNum(int $id, int $num)
    {
        return CartRepository::getInstance()->incNum($id, $num);
    }

    /**
     * Notes:自减
     * Author: Bruce.z
     * DateTime: 2022/6/30 16:56
     * @param $id
     * @param $num
     * @return mixed
     */
    public function decNum($id, $num)
    {
        return CartRepository::getInstance()->decNum($id, $num);
    }

    /**
     * Notes: 批量删除购物车
     * Author: Bruce.z
     * DateTime: 2022/6/30 16:57
     * @param array $ids
     * @return mixed
     */
    public function removeByIds(array $ids)
    {
        return CartRepository::getInstance()->removeByIds($ids);
    }

    /**
     * Notes: 获取购物车列表
     * Author: Bruce.z
     * DateTime: 2022/6/30 17:06
     * @param int $member_id
     * @return array
     */
    public function getList(int $member_id):array
    {
        return CartRepository::getInstance()->getList($member_id);
    }

    /**
     * Notes: 清空购物车
     * Author: Bruce.z
     * DateTime: 2022/7/1 10:30
     * @param int $member_id
     * @return bool
     */
    public function clear(int $member_id) : bool
    {
        return CartRepository::getInstance()->clear($member_id);
    }

    /**
     * Notes: 编辑单个购物车商品数量
     * Author: Bruce.z
     * DateTime: 2022/7/1 10:34
     * @param int $id
     * @param int $num
     * @return bool|int
     */
    public function editNumber(int $id, int $num)
    {
        return CartRepository::getInstance()->editNumber($id, $num);
    }

    /**
     * Notes: 更新选中状态
     * Author: Bruce.z
     * DateTime: 2022/10/17 17:44
     * @param int $member_id
     * @param int $type
     * @param bool $checked
     * @param int $id
     * @return int
     */
    public function setChecked(int $member_id, int $type = 0, bool $checked = false, int $id = 0): int
    {
        return CartRepository::getInstance()->setChecked($member_id, $type, $checked, $id);
    }
}
